/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.gss

import org.gss.styles.*
/**
 *
 * @author btilford
 */
class StyleSheet {

   
    StyleSheet() {Bootstrap.boot()}
   
    StyleSheet(Map<String,Rule> params) {
	this()
	def emc = new ExpandoMetaClass(StyleSheet.class,false)
	for(property in params.keySet()) {
	    emc."${property}" = params."$property"
	}
	emc.initialize()
	this.metaClass = emc
    }

    String toString() {	
	def str = new StringBuilder("/* Stylesheet Generated by GSS */\n\n")
	this.metaClass.methods.findAll{it.name =~ /get[A-Z]/}.each {
	    if(it.parameterTypes.size() == 0 && it.returnType == Rule.class) {
		str << this."${it.name}"()
	    }
	}
	return str
    }

    void save(File outputFile) {
	if(outputFile != null) {
	    if(!outputFile.parentFile.exists()) {
		outputFile.parentFile.mkdirs()
	    }
	    if(!outputFile.exists()) {
		outputFile.createNewFile()
	    }
	    outputFile.write(this.toString())
	}
    }

    
}

